#ifndef REGISTERDIALOG_H
#define REGISTERDIALOG_H

#include <QDialog>
#include"global.h"
#include<functional>
#include"errorqueuemgr.h"
#include<QTimer>
namespace Ui {
class RegisterDialog;
}

class RegisterDialog : public QDialog
{
    Q_OBJECT

public:
    explicit RegisterDialog(QWidget *parent = nullptr);
    void switchtoWaitpage();
    ~RegisterDialog();
signals:
    void switchtoLogin();
    void regsuccess();
    void starttimeout();
private:
    void InitHttpHandler();
public slots:
    void slot_reg_http_finish(ReqId id,QString res,Ecode error);
    void timecountdown();
private slots:
    void on_getcode_btn_clicked();



private slots:
    void onUserTextChanged(const QString& text);
    void onPasswordTextChanged();
    void onRepswTextChanged();
    void onEmailTextChanged();
    void onVerifyTextChanged(const QString& text);
    void on_confirm_btn_clicked();

    void on_return_btn_clicked();

    void on_cancel_btn_clicked();

private:
    Ui::RegisterDialog *ui;
    ErrorQueueManager m_errorManager;
    void ShowTip(QString str,bool ok);
    std::unordered_map<ReqId,std::function<void(QJsonObject&)>> m_handler;
    QTimer* m_connection_timer;
    int m_countdown;
    void setupConnections();
    bool validateField(const QString& fieldId, const QString& value);

};

#endif // REGISTERDIALOG_H
